<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Parametric Curve Fitting</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Parametric Curve Fitting</p>
<hr class="separator">
<div class="content">
<img src="images/paramcurve.png" width='540' height='480'>
<br><br>
This example demonstrates parametric curve fitting.<br><br>
In addition to linear regression, ChartDirector also supports polynomial, exponential and logarithmic regression. To create these curves, a <a href="TrendLayer.htm">TrendLayer</a> object is created using <a href="XYChart.addTrendLayer.htm">XYChart.addTrendLayer</a>, and the regressive type is set using <a href="TrendLayer.setRegressionType.htm">TrendLayer.setRegressionType</a>.
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/paramcurve.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%
// The XY data of the first data series
double[] dataX0 = {10, 35, 17, 4, 22, 29, 45, 52, 63, 39};
double[] dataY0 = {2.0, 3.2, 2.7, 1.2, 2.8, 2.9, 3.1, 3.0, 2.3, 3.3};

// The XY data of the second data series
double[] dataX1 = {30, 35, 17, 4, 22, 59, 43, 52, 63, 39};
double[] dataY1 = {1.0, 1.3, 0.7, 0.6, 0.8, 3.0, 1.8, 2.3, 3.4, 1.5};

// The XY data of the third data series
double[] dataX2 = {28, 35, 15, 10, 22, 60, 46, 64, 39};
double[] dataY2 = {2.0, 2.2, 1.2, 0.4, 1.8, 2.7, 2.4, 2.8, 2.4};

// Create a XYChart object of size 540 x 480 pixels
XYChart c = new XYChart(540, 480);

// Set the plotarea at (70, 65) and of size 400 x 350 pixels, with white background and a light grey
// border (0xc0c0c0). Turn on both horizontal and vertical grid lines with light grey color
// (0xc0c0c0)
c.setPlotArea(70, 65, 400, 350, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1);

// Add a legend box with the top center point anchored at (270, 30). Use horizontal layout. Use 10pt
// Arial Bold Italic font. Set the background and border color to Transparent.
LegendBox legendBox = c.addLegend(270, 30, false, "Arial Bold Italic", 10);
legendBox.setAlignment(Chart.TopCenter);
legendBox.setBackground(Chart.Transparent, Chart.Transparent);

// Add a title to the chart using 18 point Times Bold Itatic font.
c.addTitle("Parametric Curve Fitting", "Times New Roman Bold Italic", 18);

// Add titles to the axes using 12pt Arial Bold Italic font
c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12);
c.xAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12);

// Set the axes line width to 3 pixels
c.yAxis().setWidth(3);
c.xAxis().setWidth(3);

// Add a scatter layer using (dataX0, dataY0)
c.addScatterLayer(dataX0, dataY0, "Polynomial", Chart.GlassSphere2Shape, 11, 0xff0000);

// Add a degree 2 polynomial trend line layer for (dataX0, dataY0)
TrendLayer trend0 = c.addTrendLayer2(dataX0, dataY0, 0xff0000);
trend0.setLineWidth(3);
trend0.setRegressionType(Chart.PolynomialRegression(2));
trend0.setHTMLImageMap("{disable}");

// Add a scatter layer for (dataX1, dataY1)
c.addScatterLayer(dataX1, dataY1, "Exponential", Chart.GlassSphere2Shape, 11, 0x00aa00);

// Add an exponential trend line layer for (dataX1, dataY1)
TrendLayer trend1 = c.addTrendLayer2(dataX1, dataY1, 0x00aa00);
trend1.setLineWidth(3);
trend1.setRegressionType(Chart.ExponentialRegression);
trend1.setHTMLImageMap("{disable}");

// Add a scatter layer using (dataX2, dataY2)
c.addScatterLayer(dataX2, dataY2, "Logarithmic", Chart.GlassSphere2Shape, 11, 0x0000ff);

// Add a logarithmic trend line layer for (dataX2, dataY2)
TrendLayer trend2 = c.addTrendLayer2(dataX2, dataY2, 0x0000ff);
trend2.setLineWidth(3);
trend2.setRegressionType(Chart.LogarithmicRegression);
trend2.setHTMLImageMap("{disable}");

// Output the chart
WebChartViewer viewer = new WebChartViewer(request, "chart1");
viewer.setChart(c, Chart.SVG);

// Include tool tip for the chart
viewer.setImageMap(c.getHTMLImageMap("", "", "title='[{dataSetName}] ({x}, {value})'"));
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Parametric Curve Fitting&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Parametric Curve Fitting
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here is the chart image ****** --&gt;
    &lt;%= viewer.renderHTML(response) %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
